﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Security;

namespace BusinessLogic.Security
{
    public class CustomIdentity : System.Security.Principal.IIdentity
    {
        private FormsAuthenticationTicket _ticket;


        public CustomIdentity(FormsAuthenticationTicket ticket)
        {
            _ticket = ticket;
        }


        public string AuthenticationType
        {
            get { return "Custom"; }
        }

        public bool IsAuthenticated
        {
            get { return true; }
        }

        public string Name
        {
            get { return _ticket.Name; }
        }

        public FormsAuthenticationTicket Ticket
        {
            get { return _ticket; }
        }

        public string PassdwordHash
        {
            get
            {
                try
                {
                    string[] userDataPieces = _ticket.UserData.Split("|".ToCharArray());
                    return userDataPieces[0];
                }
                catch (Exception ex)
                {
                    return "";
                }
            }
        }

        public string LoginName
        {
            get
            {
                try
                {
                    string[] userDataPieces = _ticket.UserData.Split("|".ToCharArray());
                    return userDataPieces[1];
                }
                catch (Exception ex)
                {
                    return "";
                }
            }
        }
    }
}
